package com.jspgou.cms.manager.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jspgou.common.hibernate3.Updater;
import com.jspgou.common.page.Pagination;
import com.jspgou.cms.dao.ShopSupplierDao;
import com.jspgou.cms.entity.ShopSupplier;
import com.jspgou.cms.manager.ShopSupplierMng;

@Service
@Transactional
public class ShopSupplierMngImpl implements ShopSupplierMng {
	@Transactional(readOnly = true)
	public Pagination getPage(int pageNo, int pageSize) {
		Pagination page = dao.getPage(pageNo, pageSize);
		return page;
	}

	@Transactional(readOnly = true)
	public ShopSupplier findById(Long id) {
		ShopSupplier entity = dao.findById(id);
		return entity;
	}

	public ShopSupplier save(ShopSupplier bean) {
		dao.save(bean);
		return bean;
	}

	public ShopSupplier update(ShopSupplier bean) {
		Updater<ShopSupplier> updater = new Updater<ShopSupplier>(bean);
		ShopSupplier entity = dao.updateByUpdater(updater);
		return entity;
	}

	public ShopSupplier deleteById(Long id) {
		ShopSupplier bean = dao.deleteById(id);
		return bean;
	}
	
	public ShopSupplier[] deleteByIds(Long[] ids) {
		ShopSupplier[] beans = new ShopSupplier[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}

	private ShopSupplierDao dao;

	@Autowired
	public void setDao(ShopSupplierDao dao) {
		this.dao = dao;
	}
	
	public Pagination getShopSupplierPage(String merchantid, int pageNo,
			int pageSize) {
		Pagination page = dao.getPageByTag(merchantid, pageNo, pageSize);
		return page;
	}
}